﻿#region 命名空间

using System;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.WebUI.Admin.Member
{
    public partial class Edit : WebFactory.PageBase
    {
        private MemberManage _myBll = PolicyInjection.Create<MemberManage>();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;
                Edit_Load();
            }
        }

        private void Edit_Load()
        {
            var model = new UserManage().GetInfo(int.Parse(Request["ID"]));

            this.Breadcrumb1.Items.Add(new ListItem {Text = "会员中心", Value = "Member.aspx"});
            this.Breadcrumb1.Items.Add(model.UserName);
            this.Breadcrumb1.Items.Add("修改信息");

            this.lblName.Text = model.UserName;
            this.txtHomePage.Text = model.HomePage;
            this.txtQQ.Text = model.QQ;
            this.txtPetName.Text = model.PetName;
            this.txtIntroduce.Text = model.Introduce;
            this.txtemail.Text = model.EMail;

            this.txtQuestion.Text = model.Question;
            this.txtAnswer.Text = model.Answer;
            this.RBL_Sex.SelectedValue = model.Sex.ToString();
            this.txtTrueName.Text = model.TrueName;
            this.txtMSN.Text = model.Msn;
            this.txtBirthday.Text = model.Birthday;
            //txtProvince.Text = model.Province;
            //txtCity.Text = model.City;
            this.txtICQ.Text = model.Icq;
            this.txtYahoo.Text = model.Yahoo;
            this.txtSkype.Text = model.Skype;
            //txtLocation.Text = model.Location;
            this.txtIdCard.Text = model.IdCard;
            this.txtMobile.Text = model.Mobile;
            this.txtPhone.Text = model.Phone;
            this.txtAddress.Text = model.Address;

            this.NtxtCoin.Text = model.Coin.ToString();
            this.NtxtPoint.Text = model.Point.ToString();
            this.ddlActiveType.SelectedValue = model.ActiveType.ToString();

            if (model.Mature != null)
                this.txtMature.Value = model.Mature.Value.ToString("yyyy-MM-dd");
            this.NtxtExperience.Text = model.Experience.ToString();


            this.RBL_IsLocked.SelectedValue = model.IsLocked.ToString();
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            var model = new UserManage().GetInfo(int.Parse(Request["ID"]));


            model.Id = int.Parse(Request["ID"]);
            model.UserName = this.lblName.Text;
            model.HomePage = this.txtHomePage.Text.Trim();
            model.QQ = this.txtQQ.Text.Trim();
            model.PetName = this.txtPetName.Text.Trim();
            model.Introduce = this.txtIntroduce.Text.Trim();
            model.EMail = this.txtemail.Text.Trim();
            model.Question = this.txtQuestion.Text.Trim();
            model.Answer = this.txtAnswer.Text.Trim();
            model.Sex = byte.Parse(this.RBL_Sex.SelectedValue);
            model.TrueName = this.txtTrueName.Text.Trim();
            model.Msn = this.txtMSN.Text.Trim();
            model.Birthday = this.txtBirthday.Text.Trim();
            model.Icq = this.txtICQ.Text.Trim();
            model.Yahoo = this.txtYahoo.Text.Trim();
            model.Skype = this.txtSkype.Text.Trim();
            model.Location = "";
            model.IdCard = this.txtIdCard.Text.Trim();
            model.Mobile = this.txtMobile.Text.Trim();
            model.Phone = this.txtPhone.Text.Trim();
            model.Address = this.txtAddress.Text.Trim();
            model.Coin = int.Parse(this.NtxtCoin.Text);
            model.Point = int.Parse(this.NtxtPoint.Text);

            model.Experience = int.Parse(this.NtxtExperience.Text);
            model.ActiveType = byte.Parse(this.ddlActiveType.SelectedValue);
            model.IsLocked = Convert.ToInt32(this.RBL_IsLocked.SelectedValue);


            DateTime mature;
            if (DateTime.TryParse(this.txtMature.Value, out mature))
            {
                model.Mature = mature;
            }

            //model.Province = txtProvince.Text.Trim();
            //model.City = txtCity.Text.Trim();

            string strErr = null;

            new Public_Member(false).Add(model, ref strErr);

            if (string.IsNullOrEmpty(strErr) == false)
            {
                MsgBox.Message(strErr, this);
            }
            else
            {
                MsgBox.Message("修改成功！", "Member.aspx", this);
            }
        }
    }
}